package com.xomily.web.controller.system;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xomily.common.annotation.Log;
import com.xomily.common.core.controller.BaseController;
import com.xomily.common.core.domain.AjaxResult;
import com.xomily.common.enums.BusinessType;
import com.xomily.system.domain.SysSecurityKnowledge;
import com.xomily.system.service.ISysSecurityKnowledgeService;
import com.xomily.common.utils.poi.ExcelUtil;
import com.xomily.common.core.page.TableDataInfo;

/**
 * 安全知识学习Controller
 *
 * @author ruoyi
 * @date 2025-04-05
 */
@RestController
@RequestMapping("/system/knowledge")
public class SysSecurityKnowledgeController extends BaseController {
    @Autowired
    private ISysSecurityKnowledgeService sysSecurityKnowledgeService;

    /**
     * 查询安全知识学习列表
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSecurityKnowledge sysSecurityKnowledge) {
        startPage();
        List<SysSecurityKnowledge> list = sysSecurityKnowledgeService.selectSysSecurityKnowledgeList(sysSecurityKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出安全知识学习列表
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:export')")
    @Log(title = "安全知识学习", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSecurityKnowledge sysSecurityKnowledge) throws IOException {
        List<SysSecurityKnowledge> list = sysSecurityKnowledgeService.selectSysSecurityKnowledgeList(sysSecurityKnowledge);
        ExcelUtil<SysSecurityKnowledge> util = new ExcelUtil<SysSecurityKnowledge>(SysSecurityKnowledge.class);
        util.exportExcel(response, list, "安全知识学习数据");
    }

    /**
     * 获取安全知识学习详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysSecurityKnowledgeService.selectSysSecurityKnowledgeById(id));
    }

    /**
     * 新增安全知识学习
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:add')")
    @Log(title = "安全知识学习", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSecurityKnowledge sysSecurityKnowledge) {
        return toAjax(sysSecurityKnowledgeService.insertSysSecurityKnowledge(sysSecurityKnowledge));
    }

    /**
     * 修改安全知识学习
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:edit')")
    @Log(title = "安全知识学习", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSecurityKnowledge sysSecurityKnowledge) {
        return toAjax(sysSecurityKnowledgeService.updateSysSecurityKnowledge(sysSecurityKnowledge));
    }

    /**
     * 删除安全知识学习
     */
    @PreAuthorize("@ss.hasPermi('system:knowledge:remove')")
    @Log(title = "安全知识学习", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysSecurityKnowledgeService.deleteSysSecurityKnowledgeByIds(ids));
    }
}
